﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace YayiMgr.EntityFrameworkCore.Migrations
{
    /// <inheritdoc />
    public partial class _04 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "DailiId",
                table: "Suppliers");

            migrationBuilder.DropColumn(
                name: "IsRoot",
                table: "Suppliers");

            migrationBuilder.RenameColumn(
                name: "IsDaili",
                table: "Suppliers",
                newName: "IsProxy");

            migrationBuilder.CreateTable(
                name: "Manufacturers",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ManufacturerName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "生产厂家名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ContactName = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "联系人姓名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ContactTitle = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "联系人职位")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Address = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "地址")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PostalCode = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "邮政编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Phone = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "联系电话")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Fax = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "传真号码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Email = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "电子邮箱")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Website = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "网站地址")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    TaxID = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true, comment: "税务登记号")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LicenseNumber = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true, comment: "营业执照号码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Notes = table.Column<string>(type: "longtext", nullable: true, comment: "备注")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CompanyId = table.Column<Guid>(type: "char(36)", nullable: false, comment: "企业ID", collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Manufacturers", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "SupplierFacturerMapping",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    SuppliersId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ManufacturersId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SupplierFacturerMapping", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Manufacturers");

            migrationBuilder.DropTable(
                name: "SupplierFacturerMapping");

            migrationBuilder.RenameColumn(
                name: "IsProxy",
                table: "Suppliers",
                newName: "IsDaili");

            migrationBuilder.AddColumn<Guid>(
                name: "DailiId",
                table: "Suppliers",
                type: "char(36)",
                nullable: true,
                comment: "代理公司的ID",
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<bool>(
                name: "IsRoot",
                table: "Suppliers",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false,
                comment: "是否是根节点，在列表中展示");
        }
    }
}
